﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _5._2
{
    class Program
    {

        static private List<int> nums = new List<int>();

        static public void CreateNums(int n)
        {
            int flag = 0;
            Random random = new Random();
            for (int i = 0; i < n; i++)
            {
                nums.Add(random.Next(1001));
                Console.Write(nums[i] + " ");
                flag++;
                if (flag == 8)
                {
                    Console.Write("\n");
                    flag = 0;
                }
            }
            Console.Write("\n\n");
            return;
        }

        static void sort()
        {
            
            try{
                var query = from n in nums orderby n descending select n;
                int sum = query.Sum(s => s);
                double average = query.Average(s => s);
                Console.WriteLine("和:" + sum + "  平均数:" + average + "\n");
                Console.WriteLine("排序后:");
                int flag = 0;
                foreach (int i in query)
                {
                    Console.Write(i + " ");
                    flag++;
                    if (flag == 8)
                    {
                        Console.Write("\n");
                        flag = 0;
                    }
                }
            }
            catch (Exception)
            {

            }
            
        }
        static void Main(string[] args)
        {

            CreateNums(100);
            sort();
        }

       

        
        
    }
}
